<template>
  <div class="login_container">
    <div class="login_box">
      <!-- 图片区域 -->
      <div class="avatar_box">
        <img src="https://gitee.com/zj095/cloudimg/raw/master/202110230927846.png" alt="">
      </div>
      <div class="box_2">
         <div class="logo">
        <img src="https://gitee.com/zj095/cloudimg/raw/master/202110230931189.png" alt="">
      </div>
      <el-form
        ref="loginFormRef"
        :model="loginForm"
        label-width="0px"
        class="login_form"
        :rules="loginFormRules"
      >
        <!-- 用户名 -->
        <el-form-item prop="account">
          <el-input
            v-model="loginForm.account"
            prefix-icon="iconfont icon-user"
          ></el-input>
        </el-form-item>
        <!-- 密码 -->
        <el-form-item prop="password">
          <el-input
            v-model="loginForm.password"
            prefix-icon="iconfont icon-3702mima"
            type="password"
          ></el-input>
        </el-form-item>
        <!-- 忘记密码 -->
        <el-form-item class="forget">
          <router-link
            :to="{ path: '/forget'}"
            replace
          >忘记密码？</router-link>
        </el-form-item>
        <!-- 按钮区域 -->
        <el-form-item class="btn">
          <el-button
            @click="register"
          >注册</el-button>
          <el-button
            type="primary"
            @click="login"
             size="medium"
          >登录</el-button>
        </el-form-item>
      </el-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loginForm: {
        account: "",
        password: "",
      },
      loginFormRules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
     register() {
    this.$router.push('/register')
    },
    async login() {
      // this.$router.push("/home");
     const{data: res} = await this.$http.post('/api/user/studentlogin',this.loginForm)
      console.log(res);
      if(res.code == 200){
        this.$message.success("登录成功！")
        this.$router.push('/home')
        sessionStorage.setItem('accounts',this.loginForm.account)
        sessionStorage.setItem('token',res.data.token)
      }
      if(res.code == 100){
      this.$message.error("登录失败！")
    }
    },
  },
};
</script>

<style scoped>
.login_container {
  background: url("https://s3.bmp.ovh/imgs/2021/10/8da24c0a1fab482c.png");
  height: 100%;
}

.login_box {
  width: 650px;
  height: 350px;
  background:#fff;
  /* filter:alpha(opacity:30);
  opacity:9.8; */
  border-radius: 10px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.avatar_box {
  height: 300px;
  width: 300px;
  /* border: 1px solid #eee; */
  /* border-radius: 50%; */
  /* box-shadow: 0 0 10px #ddd; */
  position: absolute;
  left: 2%;
  top: 7%;
  /* transform: translate(-50%, -50%); */
  background-color: #fff;
}

.avatar_box img {
  width: 100%;
  height: 100%;
  /* border-radius: 50%; */
  background:#fff;
  /* filter:alpha(opacity:30);
  opacity:9.8; */
  border-radius: 10px;
}

.login_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 40px;
  box-sizing: border-box;
}

.forget a {
  text-decoration: none;
  color: #2b4b6b;
  float: right;
}

.btn {
  display: flex;
  justify-content: center;
}

.box_2 {
  box-sizing: border-box;
  display: flex;
  position: absolute;
 width: 386px;
 height: 300px;
 left: 43%;
}
.box_2 input {
  border-radius: 0%;
  border: none;
  border-bottom: 2px solid dodgerblue;
}
.logo {
  position: absolute;
  height: 100px;
  width: 150px;
  left: 25%;
  top: -5%;
  margin-bottom: 5%;
}
.login_form {
    position: absolute;
    bottom: 39px;
    width: 100%;
    padding: 0 40px;
    box-sizing: border-box;
    top: 6vw;
}
</style>